home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / tools / cpx_acc / cpxbasic / sources / cpx_io.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  6.6 KB  |  358 lines

  1. #include <stdarg.h>
  2. #include <ctype.h>
  3. #include <ext.h>
  4. #include <stdio.h>
  5.  
  6. #include "p2c.h"
  7. #include "glo.h"
  8.  
  9. /********************************************************************/
  10. #if TRUE!=1
  11. #undef TRUE
  12. #define TRUE 1
  13. #endif
  14.  
  15. #if FALSE!=0
  16. #undef FALSE
  17. #define FALSE 0
  18. #endif
  19.  
  20. #define POSITION_CURSOR            2
  21. #define SET_FOREGROUND_COLOR    3
  22. #define SET_BACKGROUND_COLOR    4
  23.  
  24. /********************************************************************/
  25. LOCAL    VOID    OutChar( WORD ch );
  26.  
  27. /********************************************************************/
  28. LOCAL    BYTE    buf[512];
  29. GLOBAL    WORD    cx, cy, cm, esc, chc;
  30. GLOBAL    WORD    ocx, ocy,discard;
  31. GLOBAL  int interactive;
  32. extern char rev_mode;
  33. extern void    cls(void),clline(int line);
  34. extern void cllines(int von,int bis),delxy(int line,int von,int bis);
  35. extern void ScrollUpR(int line),ScrollDownR(int line);
  36. /********************************************************************/
  37.  
  38. GLOBAL BYTE *FGets(FILE *fp, BYTE *string)
  39. {
  40.     WORD off=0, key;
  41.     char *s;
  42.     *string=0;
  43.     if(fp==stdin)
  44.     {
  45.         interactive=1;
  46.         woff=roff; /* Tastaturpuffer leeren */
  47.         while(1)
  48.         {
  49.             while(roff==woff)
  50.             {
  51.                 WaitBASIC();
  52.                 if(ctrl) return 0; /* CTRL-C */
  53.             }
  54.     
  55.             key=KeyBuffer[roff++];
  56.             if(roff>=KB_SIZE)
  57.                 roff=0;
  58.     
  59.             switch(key)
  60.             {
  61.             case 0:
  62.                 break;
  63.             case 8:
  64.             case 127:
  65.                 if(off>0)
  66.                 {
  67.                     OutChar(8);
  68.                     string[--off]=0;
  69.                 }
  70.                 break;
  71.     
  72.             case 13:
  73.                 OutChar(10);
  74.                 OutChar(13);
  75.                 interactive=0;
  76.                 return string;
  77.     
  78.             default:
  79.                 if(off<255)
  80.                 {
  81.                     string[off++]=key;
  82.                     string[off    ]=0;
  83.                 }
  84.                 OutChar(key);
  85.                 break;
  86.             }
  87.         }
  88.     }
  89.     if((s=fgets(string,255,fp))!=NULL)
  90.     {
  91.         while(*s&&*s!='\r'&&*s!='\n') s++;
  92.         *s=0;
  93.     }
  94.     else
  95.     {
  96.         fileerror=1;
  97.     }
  98.     return string;
  99. }
  100.  
  101. GLOBAL BYTE *Gets( BYTE *string)
  102. {
  103.     return FGets(stdin,string);
  104. }
  105.  
  106. GLOBAL VOID Putchar( WORD ch )
  107. {
  108.     void Bconout (int dev, int c);
  109.     if( ch==10 )
  110.     {
  111.         OutChar( 10 );
  112.         OutChar( 13 );
  113.     }
  114.     else if(ch=='\a')
  115.     {
  116.         Bconout(2,'\a');
  117.     }
  118.     else
  119.     {
  120.         OutChar( ch );
  121.     }
  122. }
  123.  
  124. GLOBAL WORD VFPRINTF(FILE *fp, BYTE *string, va_list arg )
  125. {
  126.     vsprintf(buf, string, arg);
  127.     FPUTS(buf,fp);
  128.     return (int)strlen(buf);
  129. }
  130.  
  131. GLOBAL WORD Printf( BYTE *string, ... )
  132. {
  133.     int r;
  134.     va_list arg;
  135.     va_start(arg, string);
  136.     r=VFPRINTF(stdout, string, arg);
  137.     va_end(arg);
  138.     return r;
  139. }
  140.  
  141. GLOBAL WORD FPRINTF( FILE *f, char *string, ...)
  142. {
  143.     int     r;
  144.     va_list arg;
  145.  
  146.     va_start(arg, string);
  147.     r=VFPRINTF(f,string,arg);
  148.     va_end(arg);
  149.     return r;
  150. }
  151.  
  152. GLOBAL WORD PUTC(WORD ch, FILE *f)
  153. {
  154.     int r;
  155.     if(f==stdout)
  156.     {
  157.         Putchar(ch);
  158.         return ch;
  159.     }
  160.     else
  161.     {
  162.         r=putc(ch,f);
  163.         if(r<0) fileerror=1;
  164.         return r;
  165.     }
  166. }
  167.  
  168. GLOBAL WORD FPUTS(char *string, FILE *f)
  169. {
  170.     while(*string) PUTC(*string=stdout)
  171.     {
  172.   rn ch;
  173.     }
  174. ra        {
  175.             vfvir=ft\stringaPUTC(WORD ch, FILxr;
  176. }
  177.  
  178. GLr(ch);
  179.   m)=fg
  180.         ursor muβ gelöscht werd{
  181. r;
  182. {
  183. yBuffDraw    ursor(
  184. GLOB******);
  185. D    o1;
  186.         woff
  187. D    o!= FAL==woff)
  188.             case 0D    o1;
  189. break;
  190.             ca#define SET_FOR            {
  191.     , ose
  192.     {
  193. /* CTRhc( 1[off++]=key;
  194.     cx=ch-320;
  195.                  CTRx   
  196.     cx=00;
  197.                  CTRx>=MAX_CX)
  198.     cx=MAX_CX-1(key);
  199.                 brch );
  200. {
  201. /* CTRhc( 2[off++]]=key;
  202.         cy=ch-320;
  203.                 * CTRy   
  204.     cy=00;
  205.                 * CTRy>=MAX_CY)
  206.     cy=MAX_CX-1(key);
  207. brcsc=efine(key);
  208. bcase 13:
  209.                 Oak;
  210.             ca3
  211. #define SET_BACKG:ak;
  212.             ca3
  213. #
  214. /**************:(off<255)
  215.                 {
  216.     csc=efine(key);
  217.  
  218.     if((s=fgets(strinrch );
  219. {=key;
  220. csc=efine(key);    case 0ch;;
  221. break;
  222.             ca'A':g
  223.         ursor upy);
  224. beyBuffe* CTRy>   cy--;ase 13:
  225.                 Oak;
  226.             ca'B':g
  227.         ursor d***y);
  228. beyBuffe* CTRy<(MAX_CYr=f[off++]]cyse
  229.     {
  230. /*:
  231.                 Oak;
  232.             ca'C':g
  233.         ursor forwera);
  234. beyBuffe* CTRx<(MAX_CXr=f[off++]]cxse
  235.     {
  236. /*:
  237.                 Oak;
  238.             ca'D':g
  239.         ursor backwera);
  240. beyBuffe* CTRxhar(8);
  241. ]cx--;ase 13:
  242.                 Oak;
  243.             ca'E':g
  244.         le   screen);
  245. beyBuffe*cx=cy=00;
  246.             line);ase 13:
  247.                 Oak;
  248.             ca'H':g
  249.     Home cursor    );
  250. beyBuffe*cx=cy=00;
  251.             :
  252.                 Oak;
  253.             ca'I':g
  254.     Rever        BcALSx);
  255. beyBuffe* CTRy>  off++]]cy--;ase 13ch );
  256. {
  257. /*;
  258. /******e);ase 13:
  259.                 Oak;
  260.             ca'J':g
  261.     Er        cato  r;s;
  262.  page
  263. beyBuffe*cs),delxcys1,MAX_CYr=fe 127:
  264.             'K':g
  265.         le   to  r;s;
  266.  ),de
  267. beyBuffe*n,int int
  268. GMAX_CXr=f; 8:
  269.             case 127:
  270.             'L':g
  271.     Insert L,de
  272. b;
  273. beyBuffe*;
  274. /********c
  275.         }
  276.     }cx=00;
  277.                     case 127:
  278.             'M':g
  279.     Delete L,de
  280. b;
  281. beyBuffe*;
  282. /**ownRc
  283.         }
  284.     }cx=00;
  285.                     case 1 127:
  286.             'Y':g
  287.     Position cursor    );
  288. eyBuffe*csc=#define SET_FOR;        {
  289.     , o=00;
  290.                     case 1 127:
  291.             'b':g
  292.     Set foregroFAL color    )eyBuffe*csc=3
  293. #define SET_BACKG;        {
  294.     , o=00;
  295.                     case 1 127:
  296.             'c':g
  297.     Set backgroFAL color    )eyBuffe*csc=3
  298. #
  299. /**************;        {
  300.     , o=00;
  301.                     case 1 127:
  302.             'd':g
  303.     Er        cabeginnfvis;
  304.   inplaybeyBuffe*cs),delx0,cy-=fe 127:
  305.             'o':g
  306.     Er        cabeginnfvis;
  307.  ),de
  308. beyBuffe*n,int int0,cxr=f; 8:
  309.             case 1 127:
  310.             'e':g
  311.     Enable cursor    );
  312. eyBuffe*cm=efine(key);
  313.  
  314.     if((s 127:
  315.             'f':g
  316.     Disable cursor    );
  317. eyBuffe*cm= FAL(key);
  318.  
  319.     if((s 127:
  320.             'j':g
  321.     Save cursor position;
  322. eyBuffe*ocx=cx;Buffe*ocy=cy(key);
  323.  
  324.     if((s 127:
  325.             'k':g
  326.     Restore cursor position;
  327. eyBuffe*cx=ocx;Buffe*cy=ocy(key);
  328.  
  329.     if((s 127:
  330.             'l':g
  331.     Er        caentire ),de
  332. b
  333. eyBuffe*cx=00;
  334.             lirn vocyf; 8:
  335.             case 1 127:
  336.             'p':g
  337.     Enrofid    cer        Bvideo s(vo
  338. eyBuffe*d    cls(vo=-1(key);
  339.         case 127:
  340.             'q':g
  341.     Exitid    cer        Bvideo s(vo
  342.  
  343. eyBuffe*d    cls(vo=00;
  344.                     case 127:
  345.             'v':g
  346.     Wrap at  r;s;
  347.  ),de
  348. bbeyBuffe*nintera=00;
  349.                     case 127:
  350.             'w':g
  351.     Distera at  r;s;
  352.  ),de
  353. beyBuffe*nintera=1; 8:
  354.             case 1 127:255)
  355.                 {
  356.     
  357.     if((s=fgets(string,25
  358.         BconintnBAL0ch;1;
  359.         wof    case 0ch;;
  360. b        wof
  361.                     {
  362.         
  363.     else
  364.     {ch;
  365.                      case 127
  366.                 if(of>0)
  367.                 {
  368.          CTRxhar(8);
  369. {Buffe*cx--;ase 13P
  370.  
  371. GLOB
  372. Gint' ')((s=fgets(s            case 1 127
  373.             9:ak;
  374.     x+=8e 127:
  375. x/=8e 127:
  376. x*=8e 127: CTRx>=MAX_CX)Buffe*cx=MAX_CX-1(key);        case 1 127
  377.             10    {
  378.          CT(++cyf>=MAX_CY)(8);
  379. {Buffe*cy=MAX_CY-1(key);
  380. ;
  381. /**ow()((s=fgets(s            case 1 127
  382.             12:ak;
  383.     ine);ase 1cx=cy=00;
  384.                 case 1 127
  385.             13:ak;
  386.     x=00;
  387.                 case 1 127
  388.                         {
  389.         csc= FAL(key);        case 127}tChar( ch );
  390.     }
  391. }P
  392.  
  393. GLOB
  394.  chint
  395. hORD VFPR**);
  396. Rx>=MAX_CX)Buf        wof
  397. x=MAX_CY-1(key);
  398.  nintera==woff)
  399.             x=00;
  400.         cyse
  401.     {
  402. tring,255,fRy>=MAX_CY)Buf        wof
  403. y=MAX_CY-1(key);
  404. /**ow()((s=}ch);
  405.   m)=fg
  406.         ursor neu Zeichn{
  407. r;
  408. {
  409.  
  410. yBuffDraw    ursor(
  411. GLOB****FPR**, intfourfoldf( chx0id Scy0id Scxid ScyGLr(ch)plotpod S(x0+x,y0+yf; 8:plotpod S(x0-y,y0+xf; 8:plotpod S(x0-x,y0-yf; 8:plotpod S(x0+y,y0-x****FPR**, inteightfoldf( chx0id Scy0id Scxid ScyGLr(ch)fourfoldfx0iy0ix,yf; 8:fourfoldfx0iy0ix,-B****FPR**, intcirclef( chx0id Scy0id Scr(f==stdout)x,y,q; 8:x=00;
  412. y=q=L WO    doBuf        wofeightfoldfx0iy0ix,yf; 8:    q-=x+x+1(key)xse
  413.     {
  414. ;
  415. q<0==woff)
  416.         y--;ase 1q+=y+y
  417.     {
  418. trin